﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="SerialOperation.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace CloudBlitz.DeploymentManager.DeploymentWorkflow
{
    using System;
    using System.Collections.Generic;

    public class SerialOperation : CompositeOperationBase
    {
        public SerialOperation(IEnumerable<IDeploymentOperation> operations) : base(operations)
        {
        }

        protected override OperationResult ExecuteOverride(DeploymentContext context)
        {
            foreach (var operation in this.operations)
            {
                try
                {
                    var result = operation.Execute(context);
                    if (result.Status == DeploymentOperationStatus.Failed)
                    {
                        return result;
                    }
                }
                catch (Exception e)
                {
                    return ExceptionHelper.HandleException(e);
                }
            }

            return OperationResult.Success;
        }
    }
}